package top.lanscarlos.ashcraft;

import com.google.gson.Gson;
import top.lanscarlos.ashcraft.pojo.*;

/**
 * Ashcraft
 * top.lanscarlos.ashcraft
 *
 * @author Lanscarlos
 * @since 2022-05-25 19:08
 */
public class GsonTest {
    public static void main(String[] args) {
        String json = "{\"id\":8,\"name\":\"刘华强\",\"password\":\"123\",\"gender\":1,\"money\":0.0,\"address\":\"aha\",\"phone\":\"10096\",\"regTime\":\"May 25, 2022, 7:07:16 PM\"}";
        Gson gson = new Gson();
        User user = gson.fromJson(json, User.class);
        System.out.println(user);

        Seller seller = new Seller("拼夕夕", "123", null, "az", "114514");
        Commodity commodity = new Commodity("三无产品", "给爷买", "图片.png", 9.9, 99, "废品");
        CartItem item = new CartItem(commodity);
        Cart cart = new Cart();
        cart.getItems().add(item);

        String json_cart = gson.toJson(gson.toJsonTree(cart));
        System.out.println(json_cart);
        System.out.println(gson.fromJson(json_cart, Cart.class));


    }
}
